package com.evildog.workspace.log.application.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.dependencies.mybatis.object.QueryConditionDTO;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.log.application.bo.AccessLogBO;
import com.evildog.workspace.log.application.bo.AccessLogPageBO;
import com.evildog.workspace.log.application.convert.AccessLogConvert;
import com.evildog.workspace.log.application.dto.AccessLogDTO;
import com.evildog.workspace.log.application.dto.AccessLogPageDTO;
import com.evildog.workspace.log.application.entity.AccessLog;
import com.evildog.workspace.log.application.entity.AccessLogPageDO;
import com.evildog.workspace.log.application.mapper.AccessLogMapper;
import com.evildog.workspace.log.application.service.AccessLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class AccessLogServiceImpl extends ServiceImpl<AccessLogMapper, AccessLog> implements AccessLogService {

    @Override
    public PagedResult<AccessLogPageBO> getPageList(PageQuery query, List<QueryConditionDTO> queryConditions, AccessLogPageDTO pageDTO) {
        IPage<AccessLogPageDO> page = this.baseMapper.getPageList(
                QueryConditionUtils.getPagination(query),
                queryConditions,
                pageDTO);
        return AccessLogConvert.INSTANCE.convert(page);
    }

    @Override
    public AccessLogBO getDetailById(Long id) {
        AccessLog accessLog = getById(id);
        Assert.notNull(accessLog, "accessLog is null!");
        return AccessLogConvert.INSTANCE.convert(accessLog);
    }

    @Override
    public boolean save(AccessLogDTO dto){
        AccessLog newAccessLog = AccessLogConvert.INSTANCE.convert(dto);
        return save(newAccessLog);
    }

}
